<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>">
	<meta charset="utf-8" />
	<title></title>
	<meta name="description" content="overview & stats" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
	<link rel="stylesheet" href="static/css/font-awesome.min.css" />
	<!-- 下拉框 -->
	<link rel="stylesheet" href="static/css/chosen.css" />
	<link rel="stylesheet" href="static/css/ace.min.css" />
	<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
	<link rel="stylesheet" href="static/css/ace-skins.min.css" />
	
	<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<script type="text/javascript">
		$(top.hangge());
		
		//保存
		function save(){
			if($("#roleid").val()==""){
				$("#roleid").tips({
					side:3,
		            msg:'选择角色',
		            bg:'#AE81FF',
		            time:2
		        });
				
				$("#roleid").focus();
				return false;
			}
			
			if($("#username").val()=="" || $("#username").val()=="此用户名已存在!"){
				$("#username").tips({
					side:3,
		            msg:'输入用户名',
		            bg:'#AE81FF',
		            time:2
		        });
				
				$("#username").focus();
				$("#username").val('');
				$("#username").css("background-color","white");
				return false;
			}
			//else{
			//	$("#username").val(jQuery.trim($('#username').val()));
			//}
			
			if($("#password").val()==""){
				$("#password").tips({
					side:3,
		            msg:'输入密码',
		            bg:'#AE81FF',
		            time:2
		        });
				
				$("#password").focus();
				return false;
			}
			
			if($("#password").val()!=$("#chkpwd").val()){
				$("#chkpwd").tips({
					side:3,
		            msg:'两次密码不相同',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#chkpwd").focus();
				return false;
			}
			
			if($("#nickname").val()==""){
				$("#nickname").tips({
					side:3,
		            msg:'输入姓名',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#nickname").focus();
				return false;
			}
			
			var myreg = /^(((13[0-9]{1})|159)+\d{8})$/;
			if($("#phonenumber").val()!=""){
				if($("#phonenumber").val().length != 11 && !myreg.test($("#phonenumber").val())){
					$("#phonenumber").tips({
						side:3,
			            msg:'手机号格式不正确',
			            bg:'#AE81FF',
			            time:3
			        });
					$("#phonenumber").focus();
					return false;
				}
			}
			
			if($("#email").val()!=""){
				if(!ismail($("#email").val())){
					$("#email").tips({
						side:3,
			            msg:'邮箱格式不正确',
			            bg:'#AE81FF',
			            time:3
			        });
					$("#email").focus();
					return false;
				}
			}
			
			hasUserName();
		}
		
		function ismail(mail){
			return(new RegExp(/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/).test(mail));
		}
		
		//判断用户名是否存在
		function hasUserName(){
			var username = $("#username").val();
			var url = "<%=basePath%>/newuser/hasUserName.do?username="+username+"&tm="+new Date().getTime();
			$.get(url,function(data){
				if(data=="error"){
					$("#username").tips({
						side:3,
			            msg:'此用户名已存在!',
			            bg:'#AE81FF',
			            time:3
			        });
					setTimeout("$('#username').val('')",2000);
					return false;
				}else{
					hasEmail("");
				}
			});
		}
		
		//判断邮箱是否存在
		function hasEmail(username){
			var email = $("#email").val();
			var url = "<%=basePath%>/newuser/hasEmail.do?email="+email+"&username="+username+"&tm="+new Date().getTime();
			$.get(url,function(data){
				if(data=="error"){
					$("#email").tips({
						side:3,
			            msg:'邮箱已存在',
			            bg:'#AE81FF',
			            time:3
			        });
					setTimeout("$('#email').val('')",2000);
					return false;
				}else{
					$("#userForm").submit();
					$("#centerOfMainFrame").hide();
					$("#centerOfMainFrame2").show();
				}
			});
		}
	</script>
	</head>
<body>
	<form action="<%=basePath%>/newuser/saveUser.do" name="userForm" id="userForm" method="post">
		<input type="hidden" name="currentselectorganid" id="currentselectorganid" value="${pageData.currentselectorganid }" />
		<div id="centerOfMainFrame">
			<table>
				<tr>
					<td>所属机构：<input type="text" value="${pageData.organname }" title="机构名称" readonly="readonly" style="margin-left: 12px; "/></td>
				</tr>
				<tr class="info">
					<td>所属角色：
						<select name="roleid" id="roleid" style="margin-left: 5px; ">
							<option value="">请选择角色</option>
							<c:forEach items="${roleList}" var="role">
								<option value="${role.roleid }" <c:if test="${role.roleid == pageData.roleid }">selected</c:if>>${role.rolename }</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>操作员名称：<input type="text" name="username" id="username" maxlength="32" placeholder="这里输入操作员名称" value="" title="操作员名称"/></td>
				</tr>
				<tr>
					<td>操作员密码：<input type="password" name="password" id="password"  maxlength="32" placeholder="输入密码" value="" title="密码"/></td>
				</tr>
				<tr>
					<td>确认密码：<input type="password" name="chkpwd" id="chkpwd"  maxlength="32" placeholder="确认密码" value="" title="确认密码" style="margin-left: 12px;"/></td>
				</tr>
				<tr>
					<td>操作员昵称：<input type="text" name="nickname" id="nickname"  maxlength="32" placeholder="这里输入姓名" value="" title="姓名"/></td>
				</tr>
				<tr>
					<td>手机号码：<input type="text" name="phonenumber" id="phonenumber"  maxlength="32" placeholder="这里输入手机号" value="" title="手机号" style="margin-left: 12px;"/></td>
				</tr>
				<tr>
					<td>邮件地址：<input type="email" name="email" id="email"  maxlength="32" placeholder="这里输入邮箱" title="邮箱" value="" style="margin-left: 12px;"/></td>
				</tr>
				<tr>
					<td>操作员状态：<select name="isvalid" title="状态">
						<option value="1" selected>正常</option>
						<option value="0">冻结</option>
						</select>
					</td>
				</tr>
				<tr>
					<td style="text-align: center;">
						<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
						<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					</td>
				</tr>
			</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
	</form>
	
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript">
		$(function() {
			//单选框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
		});
		</script>
	
</body>
</html>